var Fly = require("flyio/dist/npm/wx");
var fly = new Fly

fly.interceptors.request.use((config, promise) => {
    //给所有请求添加自定义header
    const token = wx.getStorageSync('sessionToken');
    if (!token) return config;

    config.headers["Authorization"] = token.sessionAuth;
    return config;
})
fly.config.baseURL = 'http://192.168.3.3:8080'


fly.interceptors.response.use(
    (response) => {
        // Do something with response data .
        // Just return the data field of response
        if (response.data.code != 0) {
            wx.showModal({
                title: '请求超时',
                content: '请重新登陆',
                success: function (res) {
                    wx.showLoading({
                        title: '加载中',
                    })
                    setTimeout(function () {
                        wx.reLaunch({ url: '../login/index' })
                        wx.hideLoading()
                    }, 300)

                }
            })

        }
        return response.data
    },
    (err) => {
        // Do something with response error
        //return Promise.resolve("ssss")
    }
)
export default fly;

